package top.datacluster.basic.algorithm.leetcode.dynamic;

import com.sun.xml.internal.ws.encoding.MtomCodec;

public class LeetCode1608 {

    public int maxProfit(int[] prices) {

        int max = 0;
        int min = Integer.MAX_VALUE;
        int i;
        for (i = 0; i < prices.length; i++){
            if (i + 1 < prices.length && prices[i + 1] <= prices[i]){
                continue;
            }else{
                break;
            }

        }
        for (; i < prices.length; i++){

            min = Math.min(min, prices[i]);
            max = Math.max(max, prices[i] - min);
        }

        return max;
    }

    public static void main(String[] args) {
        int[] test = new int[]{7,1,5,3,6,4};
        System.out.println(new LeetCode1608().maxProfit(test));
    }
}
